#include "camerainfo.h"

CameraInfo::CameraInfo() {}

bool CameraInfo::writeXML(const QXmlStreamWriter &writer){
    return true;
}

void CameraInfo::SetIPAddress(QString value){
    m_strIPAddress = value;
}

void CameraInfo::SetMACAddress(QString value){
    m_strMACAddress = value;
}

void CameraInfo::SetName(QString value){
    m_strName = value;
}

QString CameraInfo::GetName(){
    return m_strName;
}

void CameraInfo::SetCameraIdentifiers(QString value){
    m_strCameraIdentifiers = value;
}

bool CameraInfo::ReadXML(QXmlStreamReader &reader){
    QXmlStreamAttributes attributes = reader.attributes();
    if(attributes.hasAttribute("IP")) {
        m_strIPAddress = attributes.value("IP").toString();
    }
    if(attributes.hasAttribute("MAC")) {
        m_strMACAddress = attributes.value("MAC").toString();
    }
    if(attributes.hasAttribute("name")) {
        m_strName = attributes.value("name").toString();
    }
    if(attributes.hasAttribute("numbers")) {
        m_strCameraIdentifiers = attributes.value("numbers").toString();
    }

    QXmlStreamReader::TokenType token = reader.readNext();
    return true;
}

QJsonObject CameraInfo::toJson(){
    QJsonObject obj;
    obj["IPAddress"] = this->m_strIPAddress;
    obj["MACAddress"] = this->m_strMACAddress;
    obj["Name"] = this->m_strName;
    obj["CameraIdentifiers"] = this->m_strCameraIdentifiers;
    return obj;
}

void CameraInfo::fromJson(QJsonObject obj){
    this->m_strIPAddress = obj["IPAddress"].toString();
    this->m_strMACAddress = obj["MACAddress"].toString();
    this->m_strName = obj["Name"].toString();
    this->m_strCameraIdentifiers = obj["CameraIdentifiers"].toString();
}
